/*
 * Simulation.java
 *
 * Created on 20 maj 2007, 21:50
 */

package edu.uj.petri.simulation;

import edu.uj.petri.gui.MainWindowInterface;
import edu.uj.petri.model.Transition;
import edu.uj.util.Observed;
import java.util.List;

/**
 * Interface for class firing transitions.
 * @author Piotrek
 */
public interface Simulation extends Observed {
    
    /** code for Observers - list of fired transition has been cleared. */
    public final static int CLEAR_TRANSITIONS=7781;
    /**
     * code for Observers - one transition has been added.
     * Call {@link #getLastFiredTransition()}.
     */
    public final static int TRANSITION_ADDED=7782;
    /** code for Observers - one transition has been deleted */
    public final static int TRANSITION_DELETED=7783;
    /**
     * code for Observers - request for reloading list of fired transitions.
     * Call {@link #getAllFiredTransitions()}.
     */
    public final static int TRANSITION_REFRESH=7784;
    /**
     * code for Observers - simulation error occured.
     * Call {@link #getErrorMessage()}.
     */
    public final static int SIMULATION_ERROR=7785;
    
    /**
     * this method should be called before calling any other methods of this
     * class. Substitute of polimorphic constructor.
     * For use of Document.
     */
    void initialise(edu.uj.petri.document.Document document);
    
    /**
     * this method should be called just before exiting simulation
     */
    void finish();
    
    /**
     * activates all transitions capable of being fired
     */
    void showAllActiveTransitions();
    
    /**
     * fires one given transition. For use of GUI.
     * @throws SimulationException if transition is not active
     */
    void fireTransition(Transition transition) throws SimulationException;
    
    /**
     * fires given sequence of transitions. If in any moment transitions
     * which should be fired according to order in list is inactive (cannot
     * be fired), this method throws exception. For use of GUI.
     * @param transitions list of transitions to fire, first on begin of the list
     * @param delayMs between firing in miliseconds
     */
    void fireTransitions(List<Transition> transitions, int delayMs);
    
    /**
     * fires given number of randomly chosen transitions. For use of GUI.
     * @param number how many transitions
     * @param delayMs between firing in miliseconds
     */
    void fireRandomTransitions(int number, int delayMs);
    
    /**
     * adds transition name to list of fired transitions. Only for use by
     * Commands. Don't use it inside class!
     */
    void pushFiredTransition(Transition fired);
    
    /**
     * removes last fired transition from list Only for use by
     * Commands. Don't use it inside class!
     */
    void popFiredTransition();
    
    /**
     * for use of GUI
     */
    Transition getLastFiredTransition();
    
    /**
     * for use of GUI
     */
    List<Transition> getAllFiredTransitions();
    
    /**
     * returns text of error that occured during simulation.
     */
    String getErrorMessage();
    
    /**
     * forget about all fired transitions. For use of Document.
     */
    void reset();
    
    /**
     * for use of Document.
     */
    void applyTo(MainWindowInterface window);
    
}
